<template>
	<view class="content">
		<template v-if="list.length>0">
			<view class="info-item" v-for="item in list" :key="item.id"
				@click="navigate('/pages/report/form?title=我的报修'+'&id='+item.id+'&state=1')">
				<view class="text">{{item.category_text}}</view>
				<view class="time">{{item.create_time}}</view>
			</view>
		</template>
		<view v-else-if="list.length==0&&!more" style="text-align: center;">暂无数据</view>
		<view v-if="list.length>0&&!more" style="text-align: center;">没有更多了</view>
	</view>
</template>

<script>
	import {
		getApplyListApi
	} from '@/api/report.js'
	import {
		isMore
	} from '@/util/util.js'
	export default {
		data() {
			return {
				list: [],
				page: 1,
				limit: 10,
				more: true,
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getApplyListApi({
					page: this.page,
					limit: this.limit,
					//category_id: this.type
				}).then(data => {
					uni.hideLoading()
					let list = data.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.page, this.limit, data.count);
				}).catch(() => {
					uni.hideLoading()
				})
			}
		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				this.getList()
			}
		},
		onLoad(e) {
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #f7f7f7;
		padding: 30rpx;
		min-height: 100vh;

		.info-item {
			display: flex;
			flex-direction: column;
			padding: 30rpx;
			margin-bottom: 30rpx;
			background-color: #fff;
			border-radius: 20rpx;

			.text {
				font-size: 30rpx;
				word-break: break-all;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				/* 超出几行省略 */
				overflow: hidden;
				line-height: 60rpx;
			}

			.time {
				color: #999;
				font-size: 26rpx;
				margin-top: 20rpx;
			}
		}
	}
</style>